#ifndef CSCN_H_
#define CSCN_H_

#include <vector>
#include <string>
#include <irrlicht.h>

#include "scntypes.h"
#include "CScnSolid.h"
#include "CScnEnt.h"

using namespace std;
using namespace irr;
using namespace video;

enum N_TYPE{
    N_UNK1=0, N_VERTS, N_UVPOS, N_VERTIDXS, N_PLANES, N_NODES, N_SURFS, N_CELLS, N_UNK2
};

class CScn
{
private:
    void reset();
    CScnEnt * ents;
    int loadFile(std::ifstream * file);

    int loadHeader(std::ifstream * file);
    int loadEntities(std::ifstream * file);



public:
    scnHeader_t * header;
    CScnSolid * solids;

    u32 getVersion(){
        return header->version;}

    vector<CScnEnt*> cells;

    //get cell by index as defined by cell_index field
    CScnEnt * getCell(u32 cell_index);

    CScn ();
    CScn (std::ifstream * );
    ~CScn ();


    //returns pointer to CScnSolid from index or NULL if none
    CScnSolid * getSolid(u32 idx)
    {
        if (idx < header->n_solids)
            return &solids[idx];
        else
            return NULL;
    }

    //returns pointer to CScnEnt from index or NULL if none
    CScnEnt * getEnt(u32 idx)
    {
        if (idx < header->n_ents)
            return &ents[idx];
        else
            return NULL;
    }

    u32 getTotalSolids()
    {
        return header->n_solids;
    }

    u32 getTotalEnts()
    {
        return header->n_ents;
    }

};

#endif
